<template>
  
  <div class="xzgz">
    <el-breadcrumb separator="/" class="mianbao">
      <el-breadcrumb-item :to="{ path: '/index' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>假期管理</el-breadcrumb-item>
      <el-breadcrumb-item>假期规则</el-breadcrumb-item>
      <el-breadcrumb-item>新增规则</el-breadcrumb-item>
    </el-breadcrumb>

<div class="main"> &emsp; 基本设置</div>

     <el-form
      ref="ruleFormRef"
      :model="ruleForm"
      :rules="rules"
      label-width="120px"
      class="form"
      status-icon
    >
      <el-form-item label="规则名称" prop="guize">
        <el-input v-model="ruleForm.guize" />
      </el-form-item>
      <el-form-item label="适用范围" prop="fanwei">
        <el-input v-model="ruleForm.fanwei" />
      </el-form-item>
       <el-form-item label="请假时长计算" prop="time">
        <el-input v-model="ruleForm.time" />
      </el-form-item>
       <el-form-item label="状态" prop="falg">
        <el-input v-model="ruleForm.falg" />
      </el-form-item>
    </el-form>
     <div class="xinzeng">
        <el-button type="primary" @click="addnj(ruleFormRef)">
          新增年假规则
        </el-button>
        <el-button @click="addsj(ruleFormRef)" type="primary">
          新增事假规则
          </el-button>
          <el-button  @click="addhj(ruleFormRef)" type="primary">
          新增婚假规则
          </el-button>
           <el-button  @click="addcj(ruleFormRef)" type="primary">
          新增产假规则
          </el-button>
           <el-button  @click="addtx(ruleFormRef)" type="primary">
          新增调休规则
          </el-button>
           <el-button  @click="addbj(ruleFormRef)" type="primary">
          新增病假规则
          </el-button>
            <el-button  @click="addqt(ruleFormRef)" type="primary">
          新增其他规则
          </el-button>
      </div>
  </div>
</template>

<script setup>
import {nianjiatype_add,shijiatype_add,hunjiajiatype_add,chanjiatype_add,tiaoxiutype_add,bingjiatype_add,qitatype_add} from '@/api/ning/ning'
import { ref ,onMounted} from "vue";
import { useRouter} from 'vue-router'
var $router=useRouter()
var ruleFormRef=ref()
var ruleForm=ref({guize:'',fanwei:'',time:'',falg:''})
var rules=ref({
  guize: [{ required: true, message: '请输入规则名称', trigger: 'change' }],
  fanwei: [{ required: true, message: '请输入适用范围', trigger: 'change' }],
  time: [{ required: true, message: '请输入请假时长', trigger: 'change' }],
  falg: [{ required: true, message: '请输入状态', trigger: 'change' }]
})
var addnj=()=>{
    ruleFormRef.value.validate(async(valid)=>{
        if(valid){
             var ok= await nianjiatype_add(ruleForm.value)
             console.log(ok);
             ElNotification({
                title:'规则新增',
                message:'新增成功',
                type:'success',
                duration: 1500,
        })   
            $router.back();
        }else{
               ElNotification({
                title:'规则新增',
                message:'新增失败',
                type:'error',
                duration: 1500
        })  
        }
    })
}
var addsj=()=>{
    ruleFormRef.value.validate(async(valid)=>{
        if(valid){
             var ok= await shijiatype_add(ruleForm.value)
             console.log(ok);
             ElNotification({
                title:'规则新增',
                message:'新增成功',
                type:'success',
                duration: 1500,
        })   
            $router.back();
        }else{
               ElNotification({
                title:'规则新增',
                message:'新增失败',
                type:'error',
                duration: 1500
        })  
        }
    })
}
var addhj=()=>{
    ruleFormRef.value.validate(async(valid)=>{
        if(valid){
             var ok= await hunjiajiatype_add(ruleForm.value)
             console.log(ok);
             ElNotification({
                title:'规则新增',
                message:'新增成功',
                type:'success',
                duration: 1500,
        })   
            $router.back();
        }else{
               ElNotification({
                title:'规则新增',
                message:'新增失败',
                type:'error',
                duration: 1500
        })  
        }
    })
}
var addcj=()=>{
    ruleFormRef.value.validate(async(valid)=>{
        if(valid){
             var ok= await chanjiatype_add(ruleForm.value)
             console.log(ok);
             ElNotification({
                title:'规则新增',
                message:'新增成功',
                type:'success',
                duration: 1500,
        })   
            $router.back();
        }else{
               ElNotification({
                title:'规则新增',
                message:'新增失败',
                type:'error',
                duration: 1500
        })  
        }
    })
}
var addtx=()=>{
    ruleFormRef.value.validate(async(valid)=>{
        if(valid){
             var ok= await tiaoxiutype_add(ruleForm.value)
             console.log(ok);
             ElNotification({
                title:'规则新增',
                message:'新增成功',
                type:'success',
                duration: 1500,
        })   
            $router.back();
        }else{
               ElNotification({
                title:'规则新增',
                message:'新增失败',
                type:'error',
                duration: 1500
        })  
        }
    })
}
var addbj=()=>{
    ruleFormRef.value.validate(async(valid)=>{
        if(valid){
             var ok= await bingjiatype_add(ruleForm.value)
             console.log(ok);
             ElNotification({
                title:'规则新增',
                message:'新增成功',
                type:'success',
                duration: 1500,
        })   
            $router.back();
        }else{
               ElNotification({
                title:'规则新增',
                message:'新增失败',
                type:'error',
                duration: 1500
        })  
        }
    })
}
var addqt=()=>{
    ruleFormRef.value.validate(async(valid)=>{
        if(valid){
             var ok= await qitatype_add(ruleForm.value)
             console.log(ok);
             ElNotification({
                title:'规则新增',
                message:'新增成功',
                type:'success',
                duration: 1500,
        })   
            $router.back();
        }else{
               ElNotification({
                title:'规则新增',
                message:'新增失败',
                type:'error',
                duration: 1500
        })  
        }
    })
}
</script>

<style scoped lang="scss">
.mianbao {
  margin-bottom: 20px;
}
.xzgz{
   width: 100%;
  .main{
    height: 50px;
    border-bottom: 1px solid #ccc;
    background-color: white;
      display: flex;
      align-items: center;
  }
   .form{
        margin: 20px 0;
        max-width: 600px;
    }
    .xinzeng{
          display: flex;
          margin-left: 20px;
        }
}
</style>